# derived from vtk-8.1/ThirdParty/vtklibxml2

SET(PACKAGE "g3dlibxml2")
SET(VERSION "2.6.27")
SET(LIBXML_VERSION_NUMBER 20627)
SET(LIBXML_VERSION_EXTRA "")
SET(MODULE_EXTENSION ${CMAKE_SHARED_MODULE_SUFFIX})

INCLUDE(CheckLibraryExists)
INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckSymbolExists)
INCLUDE(libxml2PlatformTests.cmake)

SET(LIBXML2_PLATFORM_TEST_FILE_C platformTestsC.c)

set(CMAKE_THREAD_PREFER_PTHREAD OFF)
FIND_PACKAGE(Threads)

# Check if header file exists and add it to the list.
MACRO(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
  CHECK_INCLUDE_FILES("${LIBXML2_INCLUDES};${FILE}" ${VARIABLE})
  IF(${VARIABLE})
    SET(LIBXML2_INCLUDES ${LIBXML2_INCLUDES} ${FILE})
  ENDIF()
ENDMACRO()

# Check for headers not actually needed for the configured header but
# that may be needed to include the other headers tested.
CHECK_INCLUDE_FILE_CONCAT("stdio.h"          HAVE_STDIO_H)
CHECK_INCLUDE_FILE_CONCAT("stddef.h"         HAVE_STDDEF_H)

CHECK_INCLUDE_FILE_CONCAT("sys/types.h"      HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE_CONCAT("inttypes.h"       HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE_CONCAT("dlfcn.h"          HAVE_DLFCN_H)
CHECK_INCLUDE_FILE_CONCAT("fcntl.h"          HAVE_FCNTL_H)
CHECK_INCLUDE_FILE_CONCAT("malloc.h"         HAVE_MALLOC_H)
CHECK_INCLUDE_FILE_CONCAT("memory.h"         HAVE_MEMORY_H)
CHECK_INCLUDE_FILE_CONCAT("netdb.h"          HAVE_NETDB_H)
CHECK_INCLUDE_FILE_CONCAT("limits.h"         HAVE_LIMITS_H)
CHECK_INCLUDE_FILE_CONCAT("sys/socket.h"     HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILE_CONCAT("netinet/in.h"     HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILE_CONCAT("sys/select.h"     HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILE_CONCAT("stdint.h"         HAVE_STDINT_H)
CHECK_INCLUDE_FILE_CONCAT("stdlib.h"         HAVE_STDLIB_H)
CHECK_INCLUDE_FILE_CONCAT("string.h"         HAVE_STRING_H)
CHECK_INCLUDE_FILE_CONCAT("strings.h"        HAVE_STRINGS_H)
CHECK_INCLUDE_FILE_CONCAT("sys/stat.h"       HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE_CONCAT("sys/time.h"       HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILE_CONCAT("time.h"           HAVE_TIME_H)
CHECK_INCLUDE_FILE_CONCAT("unistd.h"         HAVE_UNISTD_H)
CHECK_INCLUDE_FILE_CONCAT("signal.h"         HAVE_SIGNAL_H)
CHECK_INCLUDE_FILE_CONCAT("errno.h"          HAVE_ERRNO_H)
CHECK_INCLUDE_FILE_CONCAT("ansidecl.h"       HAVE_ANSIDECL_H)
CHECK_INCLUDE_FILE_CONCAT("arpa/inet.h"      HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILE_CONCAT("arpa/nameser.h"   HAVE_ARPA_NAMESER_H)
CHECK_INCLUDE_FILE_CONCAT("ctype.h"          HAVE_CTYPE_H)
CHECK_INCLUDE_FILE_CONCAT("dirent.h"         HAVE_DIRENT_H)
CHECK_INCLUDE_FILE_CONCAT("dl.h"             HAVE_DL_H)
CHECK_INCLUDE_FILE_CONCAT("float.h"          HAVE_FLOAT_H)
CHECK_INCLUDE_FILE_CONCAT("fp_class.h"       HAVE_FP_CLASS_H)
CHECK_INCLUDE_FILE_CONCAT("ieeefp.h"         HAVE_IEEEFP_H)
CHECK_INCLUDE_FILE_CONCAT("math.h"           HAVE_MATH_H)
CHECK_INCLUDE_FILE_CONCAT("nan.h"            HAVE_NAN_H)
CHECK_INCLUDE_FILE_CONCAT("ndir.h"           HAVE_NDIR_H)
CHECK_INCLUDE_FILE_CONCAT("pthread.h"        HAVE_PTHREAD_H)
CHECK_INCLUDE_FILE_CONCAT("resolv.h"         HAVE_RESOLV_H)
CHECK_INCLUDE_FILE_CONCAT("stdarg.h"         HAVE_STDARG_H)
CHECK_INCLUDE_FILE_CONCAT("sys/mman.h"       HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILE_CONCAT("sys/timeb.h"      HAVE_SYS_TIMEB_H)

CHECK_SYMBOL_EXISTS(finite        "${LIBXML2_INCLUDES}" HAVE_FINITE)
CHECK_SYMBOL_EXISTS(fpclass       "${LIBXML2_INCLUDES}" HAVE_FPCLASS)
CHECK_SYMBOL_EXISTS(fp_class      "${LIBXML2_INCLUDES}" HAVE_FP_CLASS)
CHECK_SYMBOL_EXISTS(fprintf       "${LIBXML2_INCLUDES}" HAVE_FPRINTF)
CHECK_SYMBOL_EXISTS(ftime         "${LIBXML2_INCLUDES}" HAVE_FTIME)
CHECK_SYMBOL_EXISTS(gettimeofday  "${LIBXML2_INCLUDES}" HAVE_GETTIMEOFDAY)
CHECK_SYMBOL_EXISTS(localtime     "${LIBXML2_INCLUDES}" HAVE_LOCALTIME)
CHECK_SYMBOL_EXISTS(printf        "${LIBXML2_INCLUDES}" HAVE_PRINTF)
CHECK_SYMBOL_EXISTS(sscanf        "${LIBXML2_INCLUDES}" HAVE_SSCANF)
CHECK_SYMBOL_EXISTS(sprintf       "${LIBXML2_INCLUDES}" HAVE_SPRINTF)
CHECK_SYMBOL_EXISTS(snprintf      "${LIBXML2_INCLUDES}" HAVE_SNPRINTF)
CHECK_SYMBOL_EXISTS(signal        "${LIBXML2_INCLUDES}" HAVE_SIGNAL)
CHECK_SYMBOL_EXISTS(strdup        "${LIBXML2_INCLUDES}" HAVE_STRDUP)
CHECK_SYMBOL_EXISTS(strndup       "${LIBXML2_INCLUDES}" HAVE_STRNDUP)
CHECK_SYMBOL_EXISTS(strerror      "${LIBXML2_INCLUDES}" HAVE_STRERROR)
CHECK_SYMBOL_EXISTS(strftime      "${LIBXML2_INCLUDES}" HAVE_STRFTIME)
CHECK_SYMBOL_EXISTS(stat          "${LIBXML2_INCLUDES}" HAVE_STAT)
CHECK_SYMBOL_EXISTS(_stat         "${LIBXML2_INCLUDES}" HAVE__STAT)
CHECK_SYMBOL_EXISTS(stat64        "${LIBXML2_INCLUDES}" HAVE_STAT64)
CHECK_SYMBOL_EXISTS(_stat64       "${LIBXML2_INCLUDES}" HAVE__STAT64)
CHECK_SYMBOL_EXISTS(vfprintf      "${LIBXML2_INCLUDES}" HAVE_VFPRINTF)
CHECK_SYMBOL_EXISTS(vsnprintf     "${LIBXML2_INCLUDES}" HAVE_VSNPRINTF)
CHECK_SYMBOL_EXISTS(vsprintf      "${LIBXML2_INCLUDES}" HAVE_VSPRINTF)

LIBXML2_PLATFORM_C_TEST(HAVE_GETADDRINFO "Checking for getaddrinfo." DIRECT)
LIBXML2_PLATFORM_C_TEST(HAVE_SOCKLEN_T   "Checking for socklen_t" DIRECT)
LIBXML2_PLATFORM_C_TEST(HAVE_SYS_DIR_H   "Checking for DIR in sys/dir.h" DIRECT)
LIBXML2_PLATFORM_C_TEST(HAVE_SYS_NDIR_H  "Checking for DIR in sys/ndir.h" DIRECT)
LIBXML2_PLATFORM_C_TEST(HAVE_VA_COPY     "Checking for va_copy" DIRECT)
LIBXML2_PLATFORM_C_TEST(HAVE___VA_COPY   "Checking for __va_copy" DIRECT)
LIBXML2_PLATFORM_C_TEST(SUPPORT_IP6      "Checking for ipv6 support." DIRECT)

SET(WITH_TRIO 0)
SET(WITH_THREADS 1)
SET(WITH_TREE 1)
SET(WITH_OUTPUT 1)
SET(WITH_PUSH 1)
SET(WITH_READER 1)
SET(WITH_PATTERN 1)
SET(WITH_WRITER 1)
SET(WITH_SAX1 0)
SET(WITH_FTP 0)  # fix socket API
SET(WITH_HTTP 0) # fix socket API
SET(WITH_VALID 1)
SET(WITH_HTML 0)
SET(WITH_LEGACY 0)
SET(WITH_C14N 1)
SET(WITH_CATALOG 1)
SET(WITH_DOCB 1)
SET(WITH_XPATH 1)
SET(WITH_XPTR 1)
SET(WITH_XINCLUDE 1)
SET(WITH_ICONV 0)
SET(WITH_ISO8859X 1)
SET(WITH_DEBUG 0)
SET(WITH_MEM_DEBUG 0)
SET(WITH_RUN_DEBUG 0)
SET(WITH_REGEXPS 1)
SET(WITH_SCHEMAS 1)
SET(WITH_SCHEMATRON 1)
SET(WITH_MODULES 1)
SET(WITH_ZLIB 0)

# Create the platform configuration header.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config_cmake.h.in
               ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)

# Create the build configuration header.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/libxml/xmlversion.h.in
               ${CMAKE_CURRENT_SOURCE_DIR}/include/libxml/xmlversion.h @ONLY)
